package com.sxj.corejava.code14_Lambda表达式;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class Test05_函数型接口 {

    public static void main(String[] args) {
        // 匿名内部类用法
        List<Integer> list = Arrays.asList(1,2,3,4,5,6,7,8);
        Integer length = testFunction(new Function<List<Integer>, Integer>() {
            @Override
            public Integer apply(List<Integer> integers) {
                return integers.size();
            }
        },list);
        System.out.println("集合长度为:"+length);

        // Lambda表达式用法
        length = testFunction(a -> a.size(),list);
        System.out.println(length);
    }

    /**
     * 函数型接口,R apply(T t);
     * @param function
     * @param list
     * @return
     */
    public static Integer testFunction(Function<List<Integer>,Integer> function, List<Integer> list){
        return function.apply(list);
    }

}
